package com.anycl.springboot.springbootinaction.entity;

import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

@Data
@NoArgsConstructor
public class User {
    public interface UserView {}

    public interface UserDetailView extends UserView {

    }

    @JsonView(UserView.class)
    private Long id;

    @JsonView(UserView.class)
    @NotNull
    @Size(min = 2, max = 10)
    private String username;

    @JsonView(UserDetailView.class)
    @NotNull
    @Size(min = 5, max = 20)
    private String password;

    @JsonView(UserDetailView.class)
    private Date createTime;

    @JsonView(UserDetailView.class)
    private Date updateTime;

    private MultipartFile file;

    public User(Long id, String username, String password) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.createTime = new Date();
        this.updateTime = new Date();
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
        this.createTime = new Date();
        this.updateTime = new Date();
    }
}
